<?php

if (!$usr->checkPermission('mod_newsletter_tables','u'))
{
    print "<b>Sie haben nicht die entsprechenden Rechte, um die Tabellen einzurichten!</b>";
    exit;
}

if ($env->param('createTables')){
 if ($env->param('entries')){
   print "Erzeuge Eintr&auml;ge<br>";
   $udba->query("Drop table if exists ".$tableforwarder."_modNewsletter_entries;");
   $udba->query("create table ".$tableforwarder."_modNewsletter_entries (".
        "id int unsigned not NULL auto_increment, instance varchar(40) not null, " .
        "name varchar(255), email varchar(255) not null, cellphone varchar(255), " .
        "code varchar(100), primary key(id), unique(instance, email), " .
        "index(instance));");
   $udba->query("Drop table if exists ".$tableforwarder."_modNewsletter_rmentries;");
   $udba->query("create table ".$tableforwarder."_modNewsletter_rmentries (".
        "id int unsigned not NULL auto_increment, instance varchar(40) not null, " .
        "name varchar(255), email varchar(255) not null, cellphone varchar(255), " .
        "code varchar(100), primary key(id), " .
        "index(instance));");
   $udba->query("Drop table if exists ".$tableforwarder."_modNewsletter_letter;");
   $udba->query("create table ".$tableforwarder."_modNewsletter_letter (".
        "id int unsigned not NULL auto_increment, instance varchar(40) not null,".
        "headline varchar(255) not null, body text not null, date bigint, " .
        "primary key(id), index(instance));");
   $udba->query("Drop table if exists ".$tableforwarder."_modNewsletter_conf;");
   $udba->query("create table ".$tableforwarder."_modNewsletter_conf (" .
        "instance varchar(40) not null, from_email varchar(255), " .
        "reply_to_email varchar(255), organization varchar(255), " .
        "link varchar(255), index(instance));");
 }
} else {
?>
<?php echo $udba->getError() ?>
<form action="<?=$scriptname?>" method="GET">
                <input type="hidden" name="module" value="<?=$module?>">
                <input type="hidden" name="instance" value="<?=$instance?>">
                <input type="hidden" name="target" value="createTables.php">
                <input type="hidden" name="createTables" value="true">
        <input type="checkbox" value="on" name="entries">Eintr&auml;ge und Mails<br>
        <input type="submit" class="button" value="einrichten">
</form>
<?php
}
?>